import requests

from DjangoDemo.scripts import GetToken


class Get_Site_Message:
    def __init__(self):
        self.get_Token = GetToken.Get_Token()  # token对象
        # 定义接口的 URI
        GET_SITES_URL = "/controller/campus/v3/sites"  # 局部变量
        # 配置 URL 和 Headers
        self.get_sites_url = "https://" + self.get_Token.host + ":" + self.get_Token.port + GET_SITES_URL
        self.headers_get = {'Content-Type': 'application/json', 'Accept': 'application/json',
                            'X-AUTH-TOKEN': self.get_Token.token_id}
        # 发起请求
        self.r = requests.get(self.get_sites_url, headers=self.headers_get, verify=False)
        print(type(self.r))
        self.total_records = self.r.json()['totalRecords']


if __name__ == "__main__":  # test

    site_message = Get_Site_Message()

    # 解析站点信息
    print("2.【Get Sites Info】")
    print("【get_sites_url】：" + site_message.get_sites_url)

    print("【total_records】：" + str(site_message.total_records))
    print(site_message.r.text)
